const cry = require("../util/crypt")
const {pathToRegexp} = require("path-to-regexp")//解析字符串生成正则规则
const {getErr} = require("./getResult");
//pathToRegexp
const servAdmin = require("../sever/serveAdmin")
module.exports =  function(req,res,next){
        
    
    if(req.path !=="/api/book/findBook" && req.path !=="/api/book/getBookType"
        && req.path !=="/api/book/getBookTop"
       && req.path !=="/api/book/search" && req.path !=="/api/book/getUserTop" 
      && req.path.substr(0,6) !=="/imgs/" && req.path !== '/api/user/login'
      && req.path !== '/api/admin/login'
      ){
        const token = req.cookies.userId;
        const tokenAdmin = req.cookies.adminId
        console.log("req.cookies",req.cookies.adminId);
        if(token){
          req.userId = cry.decrypto(token);
        }
        if(tokenAdmin){
            req.adminId = cry.decrypto(tokenAdmin);

        }
        next();
        return;
    }
    next();

}